<template>
  <el-container class="main">
    <!---header-->
    <el-header>
      <div class="filter-container">
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-circle-plus-outline"
          @click="opendialog(1, {})"
        >添加顶级分类</el-button>
        <span>位置：</span>
        <el-select
          v-model="posTyp"
          class="filter-item"
          placeholder="请选择位置"
          @change="getProductDocTyp()"
        >
          <el-option label="产品文档" :value="0" />
          <el-option label="常见问题" :value="1" />
        </el-select>
      </div>
    </el-header>
    <!---header-->

    <!--content-->
    <el-container>
      <el-aside width>
        <div v-loading="treeloading" class="custom-tree-container">
          <div ref="blocref" class="block">
            <el-tree
              :data="Treedata"
              node-key="typID"
              default-expand-all
              :highlight-current="true"
              :expand-on-click-node="false"
              :style="{ height: bottom + 'px' }"
              @node-click="getNode"
            >
              <span slot-scope="{ node, data }" class="custom-tree-node">
                <span>{{ node.label }}</span>
                <span>
                  <el-button
                    type="text"
                    icon="el-icon-circle-plus-outline"
                    title="添加节点"
                    circle
                    @click.stop="() => opendialog(1, data)"
                  >添加</el-button>
                  <el-button
                    type="text"
                    icon="el-icon-edit"
                    title="修改节点"
                    circle
                    @click.stop="() => opendialog(0, data)"
                  >修改</el-button>
                  <el-popover
                    v-model="node.isVisible"
                    placement="top"
                    width="160"
                  >
                    <p>是否确定删除吗？</p>
                    <div style="text-align: right; margin: 0">
                      <el-button
                        size="mini"
                        type="text"
                        @click.stop="node.isVisible = false"
                      >取消</el-button>
                      <el-button
                        type="primary"
                        size="mini"
                        @click.stop="IsShow(node, data, '1')"
                      >确定</el-button>
                    </div>
                    <el-button
                      slot="reference"
                      type="text"
                      icon="el-icon-delete"
                      title="删除"
                      circle
                      @click.stop=""
                    >删除</el-button>
                  </el-popover>
                  <el-button
                    v-if="data.stt == 1"
                    type="text"
                    title="状态"
                    :style="{ color: 'green', 'font-size': '12px' }"
                    circle
                    @click.stop="() => IsShow(node, data, '0')"
                  >显示</el-button>
                  <el-button
                    v-else-if="data.stt == 0 && data.isdisable"
                    type="text"
                    title="状态"
                    :style="{ color: '#909399', 'font-size': '12px' }"
                    circle
                  >隐藏</el-button>
                  <el-button
                    v-else-if="data.stt == 0 && data.isdisable == false"
                    type="text"
                    title="状态"
                    :style="{ color: 'red', 'font-size': '12px' }"
                    circle
                    @click.stop="() => IsShow(node, data, '0')"
                  >隐藏</el-button>
                </span>
              </span>
            </el-tree>
          </div>
        </div>
      </el-aside>
      <el-main>
        <div v-loading="loading" class="productdoctypcontent">
          <el-collapse v-model="activeNames" :style="{ height: bottom + 'px' }">
            <el-collapse-item title="分类信息:" name="1">
              <el-form
                :model="form"
                :inline="true"
                label-position="left"
                label-width="120px"
                style="text-align: left"
              >
                <el-form-item label="展示方式" class="labeldiv">
                  <el-select
                    v-model="form.showTyp"
                    class="filter-item"
                    placeholder="请选择展示方式"
                    style="width: 300px"
                    @change="fetchData()"
                  >
                    <el-option label="单个文档" :value="0" />
                    <el-option label="列表" :value="1" />
                  </el-select>
                </el-form-item>
                <el-form-item label="分类名称">
                  <el-input
                    v-model="form.name"
                    placeholder="请输入分类名称"
                    style="width: 300px"
                  />
                </el-form-item>
                <br>
                <el-form-item label="显示顺序">
                  <el-input
                    v-model="form.rdx"
                    placeholder="请输入显示顺序"
                    style="width: 300px"
                  />
                </el-form-item>
                <el-form-item label="上级">
                  <el-select
                    v-model="form.prtID"
                    placeholder="请选择上级"
                    style="width: 300px"
                  >
                    <el-option
                      style="font-size: 16px"
                      label="顶级分类"
                      value=""
                    />
                    <el-option
                      v-for="item in TypList"
                      :key="item.typID"
                      :label="item.name"
                      :value="item.typID"
                    />
                  </el-select>
                </el-form-item>
              </el-form>
            </el-collapse-item>

            <el-collapse-item title="内容信息:" name="2">
              <div v-if="form.showTyp == 0">
                <div class="item">
                  <div class="namediv">标题名称：</div>
                  <el-input
                    v-model="desform.name"
                    class="iteminput"
                    placeholder="请输入标题名称"
                  />
                </div>

                <div class="item">
                  <div class="namediv">状态：</div>
                  <el-select v-model="desform.stt" class="iteminput">
                    <el-option label="显示" :value="1" />
                    <el-option label="隐藏" :value="0" />
                  </el-select>
                </div>
                <div class="item">
                  <div class="namediv">开始日期：</div>
                  <el-date-picker
                    v-model="desform.stDt"
                    type="datetime"
                    placeholder="请选择开始日期"
                    format="yyyy-MM-dd HH:mm:ss"
                    style="width: 300px"
                  />
                </div>
                <div class="item">
                  <div class="namediv">结束日期：</div>
                  <el-date-picker
                    v-model="desform.etDt"
                    style="width: 300px"
                    type="datetime"
                    placeholder="请选择结束日期"
                    format="yyyy-MM-dd HH:mm:ss"
                  />
                </div>
                <div class="item">
                  <div class="namediv">显示顺序：</div>
                  <el-input
                    v-model="desform.rdx"
                    type="num"
                    class="iteminput"
                    placeholder="请输入显示顺序"
                  />
                </div>

                <div class="itemcontent">
                  <!-- <div style="text-align: left">内容：</div> -->
                  <Tinymce
                    ref="editor"
                    v-model="desform.content"
                    :height="bottom / 2.5"
                  />
                </div>
                <div class="dialog-footer">
                  <el-button type="primary" @click="saveDes()">保 存</el-button>
                </div>
              </div>
              <!--table-->
              <div class="adddesdiv">
                <el-button
                  v-if="form.showTyp == 1"
                  type="text"
                  icon="el-icon-circle-plus-outline"
                  title="添加内容信息"
                  circle
                  @click.stop="() => opendesdialog(1, {})"
                >添加内容信息</el-button>
              </div>

              <el-table
                v-if="form.showTyp == 1"
                v-loading="tableloading"
                :style="{ 'margin-top': '0' }"
                :data="deslist"
                border
                fit
                highlight-current-row
                style="width: 100%"
              >
                <el-table-column label="标题名称" align="left">
                  <template slot-scope="{ row }">
                    <span>{{ row.name }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="显示顺序" align="left">
                  <template slot-scope="{ row }">
                    <span>{{ row.rdx }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="显示时间" align="center">
                  <template slot-scope="{ row }">
                    <span>{{ row.stDt }}</span><br>
                    <span>{{ row.etDt }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="状态" align="center">
                  <template slot-scope="{ row }">
                    <el-button
                      v-if="row.stt == 1"
                      type="text"
                      title="状态"
                      :style="{ color: 'green' }"
                      circle
                      @click.stop="() => IsShowDes(row, '0')"
                    >显示</el-button>
                    <el-button
                      v-else
                      type="text"
                      title="状态"
                      :style="{ color: 'red' }"
                      circle
                      @click.stop="() => IsShowDes(row, '0')"
                    >隐藏</el-button>
                  </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作">
                  <template slot-scope="scope">
                    <el-button
                      type="primary"
                      size="mini"
                      @click="opendesdialog(0, scope.row)"
                    >编辑</el-button>
                    <el-popover
                      v-model="scope.row.isVisible"
                      placement="top"
                      width="160"
                    >
                      <p>是否确定删除吗？</p>
                      <div style="text-align: right; margin: 0">
                        <el-button
                          size="mini"
                          type="text"
                          @click.stop="scope.row.isVisible = false"
                        >取消</el-button>
                        <el-button
                          type="primary"
                          size="mini"
                          @click.stop="IsShowDes(scope.row, '1')"
                        >确定</el-button>
                      </div>
                      <el-button
                        slot="reference"
                        type="danger"
                        size="mini"
                        circle
                        @click.stop=""
                      >删除</el-button>
                    </el-popover>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                v-show="listQuery.total > 0 && form.showTyp == 1"
                :total="listQuery.total"
                :page.sync="listQuery.page"
                :limit.sync="listQuery.limit"
                @pagination="fetchData()"
              />
              <!--table end -->
            </el-collapse-item>
          </el-collapse>
        </div>
      </el-main>
    </el-container>
    <el-dialog
      title="分类信息"
      :visible.sync="dialogFormVisible"
      :show-close="true"
      width="55%"
    >
      <el-form
        :model="formInline"
        :inline="true"
        label-position="left"
        label-width="120px"
      >
        <el-form-item label="展示方式">
          <el-select
            v-model="formInline.showTyp"
            class="filter-item"
            placeholder="请选择展示方式"
            style="width: 300px"
          >
            <el-option label="单个文档" :value="0" />
            <el-option label="列表" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item
          label="分类名称"
          prop="name"
          :rules="[
            { required: true, message: '分类名称不能为空', trigger: 'blur' },
          ]"
        >
          <el-input
            v-model="formInline.name"
            placeholder="请输入分类名称"
            style="width: 300px"
          />
        </el-form-item>
        <br>
        <el-form-item label="显示顺序">
          <el-input
            v-model="formInline.rdx"
            placeholder="请输入显示顺序"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item label="上级">
          <el-select
            v-model="formInline.prtID"
            placeholder="请选择上级"
            style="width: 300px"
            :disabled="isadd == 1"
          >
            <el-option style="font-size: 16px" label="顶级分类" value="" />
            <el-option
              v-for="item in TypList"
              :key="item.typID"
              :label="item.name"
              :value="item.typID"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="append()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="内容信息"
      :visible.sync="dialogDesVisible"
      :show-close="true"
      width="55%"
    >
      <el-form
        :model="desform"
        :inline="true"
        label-position="left"
        label-width="120px"
      >
        <el-form-item label="标题名称">
          <el-input
            v-model="desform.name"
            placeholder="请输入标题名称"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            v-model="desform.stt"
            class="filter-item"
            placeholder="请选择状态"
            style="width: 300px"
          >
            <el-option label="显示" :value="1" />
            <el-option label="隐藏" :value="0" />
          </el-select>
        </el-form-item>
        <br>
        <el-form-item label="请选择开始日期">
          <el-date-picker
            v-model="desform.stDt"
            style="width: 300px"
            type="datetime"
            placeholder="请选择开始日期"
            format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="请选择结束日期">
          <el-date-picker
            v-model="desform.etDt"
            style="width: 300px"
            type="datetime"
            placeholder="请选择结束日期"
            format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <br>
        <el-form-item label="显示顺序">
          <el-input
            v-model="desform.rdx"
            placeholder="请输入显示顺序"
            style="width: 300px"
          />
        </el-form-item>
        <Tinymce ref="editor2" v-model="desform.content" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveDes()">确 定</el-button>
      </div>
    </el-dialog>
  </el-container>
</template>

<script>
import Tinymce from '@/components/Tinymce'
import Vue from 'vue'
import { debuglog } from 'util'
import { AjaxToken } from '@/api/common'
import { SelectAjax } from '@/api/common'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import selectcust from '@/components/Custom/select/select'
import { delimiter } from 'path'
import 'url-search-params-polyfill'

export default {
  name: 'ProductDocTyp',
  components: { Tinymce, Pagination, selectcust },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },

  data() {
    return {
      loading: false,
      treeloading: false,
      tableloading: false,
      dialogFormVisible: false,
      dialogDesVisible: false,
      activeNames: ['1', '2'],
      dialogStatus: '',
      TypList: [],
      Treedata: [],
      listQuery: {
        name: '',
        total: 0,
        page: 1,
        limit: 10
      },
      formInline: {
        showTyp: 0,
        posTyp: 0,
        name: '',
        typID: '',
        prtID: '',
        rdx: '0',
        stt: 1,
        brf: '',
        isDelete: 'N',
        uptr: '',
        uptDtt: new Date()
      },
      form: {
        showTyp: 0,
        posTyp: 0,
        name: '',
        typID: '',
        prtID: '',
        rdx: '0',
        stt: 1,
        brf: '',
        isDelete: 'N',
        uptr: '',
        uptDtt: new Date()
      },
      backform: {
        showTyp: 0,
        posTyp: 0,
        name: '',
        typID: '',
        prtID: '',
        rdx: '0',
        stt: 1,
        brf: '',
        isDelete: 'N',
        uptr: '',
        uptDtt: new Date()
      },
      desform: {
        id: '',
        content: '',
        name: '',
        typID: '',
        rdx: '0',
        stt: 1,
        brf: '',
        isDelete: 'N',
        stDt: '',
        etDt: '',
        publishDt: new Date(),
        uptr: '',
        uptDtt: new Date()
      },
      desbackform: {
        id: '',
        content: '',
        name: '',
        typID: '',
        rdx: '0',
        stt: 1,
        brf: '',
        isDelete: 'N',
        stDt: '',
        etDt: '',
        publishDt: new Date(),
        uptr: '',
        uptDtt: new Date()
      },
      deslist: [],
      isadd: 0,
      nodedata: {},
      getnodedata: {},
      bottom: 0,
      posTyp: 0,
      oldprtID: ''
    }
  },
  created() {},
  mounted() {
    this.getProductDocTyp()

    // 当前元素与底部的距离 = 可视区窗口高度 - 当前元素与页面顶部距离 - 当前元素高度
    this.bottom =
      window.innerHeight -
      this.$refs.blocref.getBoundingClientRect().y -
      this.$refs.blocref.getBoundingClientRect().height -
      10
  },
  methods: {
    // 查询产品文档说明分页
    fetchData() {
      this.tableloading = true
      this.desform = JSON.parse(JSON.stringify(this.desbackform))
      this.desform.typID = this.getnodedata.typID
      this.deslist = []
      this.listQuery.page = 1
      this.listQuery.total = 0
      var params = new URLSearchParams()
      params.append(
        'Parms',
        '{"page":' +
          this.listQuery.page +
          ',"rows":' +
          this.listQuery.limit +
          '}'
      )
      params.append('Name', this.listQuery.name)
      params.append('TypID', this.getnodedata.typID)
      backstage.getNode(this, params)
    },
    // 获取产品文档分类
    getProductDocTyp() {
      this.treeloading = true
      var params = new URLSearchParams()
      params.append('PosTyp', this.posTyp)
      backstage.getProductDocTyp(this, params)
    },
    // 打开内容信息表单
    opendesdialog(isadd, data) {
      this.dialogDesVisible = true
      if (isadd == 0) {
        // 编辑
        data.isVisible = undefined
        this.desform = JSON.parse(JSON.stringify(data))
      } else {
        // 添加
        this.desform = JSON.parse(JSON.stringify(this.desbackform))
        this.desform.typID = this.getnodedata.typID
      }
      const that = this
      setTimeout(function() {
        that.$refs.editor2.setContent(that.desform.content || '')
      }, 500)
    },
    // 打开添加分类表单
    opendialog(isadd, data) {
      this.dialogFormVisible = true
      this.isadd = isadd
      this.nodedata = data
      if (isadd == 0) {
        // 编辑
        this.formInline.name = data.label
        this.formInline.typID = data.typID
        this.formInline.prtID = data.prtID == null ? '' : data.prtID
        this.formInline.rdx = data.rdx
        this.formInline.stt = data.stt
        this.formInline.isDelete = data.isDelete
        this.formInline.posTyp = data.posTyp
        this.formInline.showTyp = data.showTyp
      } else {
        // 添加
        this.formInline = JSON.parse(JSON.stringify(this.backform))
        this.formInline.prtID = data.typID || ''
        this.formInline.stt = data.stt.toString()
      }
    },
    // 添加节点
    append() {
      if (this.formInline.name == '' || this.formInline.name == null) {
        this.$message({
          showClose: true,
          message: '分类名称不能为空',
          type: 'error'
        })
        return
      }
      if (this.formInline.rdx == null) {
        this.$message({
          showClose: true,
          message: '显示顺序不能为空',
          type: 'error'
        })
        return
      }
      this.formInline.posTyp = this.posTyp
      // //新增
      // if (this.isadd == 1) {
      //   this.formInline.stt = 1;
      // }
      var params = new URLSearchParams()
      params.append('str', JSON.stringify(this.formInline))
      backstage.append(this, params)
    },
    // 显示隐藏或者删除
    IsShow(node, data, typ) {
      this.treeloading = true
      var params = new URLSearchParams()
      params.append('TypID', data.typID)
      params.append('Val', typ == '0' ? data.stt : data.isDelete)
      params.append('Typ', typ)
      backstage.IsShow(this, params, node, data, typ)
    },
    // 显示隐藏或者删除产品文档
    IsShowDes(data, typ) {
      this.tableloading = true
      const d = JSON.parse(JSON.stringify(data))
      if (typ == '0') {
        d.stt = d.stt == 1 ? 0 : 1
      } else {
        d.isDelete = d.isDelete == 'N' ? 'Y' : 'N'
      }
      d.isVisible = undefined
      var params = new URLSearchParams()
      params.append('str', '1')
      params.append('des', JSON.stringify(d))
      backstage.saveDes(this, params, this.form.showTyp)
    },
    // 保存数据
    saveDes() {
      if (this.form.name == '' || this.form.name == null) {
        this.$message({
          showClose: true,
          message: '分类名称不能为空',
          type: 'error'
        })
        return
      }
      if (this.form.rdx == null) {
        this.$message({
          showClose: true,
          message: '分类信息显示顺序不能为空',
          type: 'error'
        })
        return
      }
      if (this.desform.name == '' || this.desform.name == undefined) {
        this.$message({
          showClose: true,
          message: '请输入标题名称',
          type: 'error'
        })
        return
      }
      if (this.desform.rdx == null) {
        this.$message({
          showClose: true,
          message: '内容信息显示顺序不能为空',
          type: 'error'
        })
        return
      }
      this.loading = true
      var params = new URLSearchParams()
      params.append('str', JSON.stringify(this.form))
      params.append('des', JSON.stringify(this.desform))
      backstage.saveDes(this, params, this.form.showTyp)
    },
    // 移除节点
    remove(node, data) {
      const parent = node.parent
      const children = parent.data.children || parent.data
      const index = children.findIndex((d) => d.typID === data.typID)
      children.splice(index, 1)
      this.Treedata = JSON.parse(JSON.stringify(this.Treedata))
    },
    // 遍历树形菜单数据
    treeMap_stt(data, typid, stt) {
      const newArr = []
      const that = this
      data.map(function(item) {
        if (item.typID == typid || item.prtID == typid) {
          item.stt = stt
          const children = item.children
          if (
            children != null &&
            children != undefined &&
            children.length > 0
          ) {
            item.children = that.treeMap_stt(children, item.typID, stt)
            if (item.stt == 0) {
              item.children = that.treeMap_isdisable(item.children, item.typID)
              if (item.prtID != null) {
                item.isdisable = false
              }
            }
          } else {
            item.isdisable = false
          }
        } else {
          const children = item.children
          if (
            children != null &&
            children != undefined &&
            children.length > 0
          ) {
            item.children = that.treeMap_stt(children, typid, stt)
          }
        }
        newArr.push(item)
      })
      return newArr
    },
    // 遍历树形菜单数据
    treeMap_name(data, typid, name, showTyp, rdx) {
      const newArr = []
      const that = this
      data.map(function(item) {
        if (item.typID == typid) {
          if (name != null) {
            item.label = name
          }
          if (showTyp != null) {
            item.showTyp = showTyp
          }
          if (rdx != null) {
            item.rdx = rdx
          }
        }
        const children = item.children
        if (children != null && children != undefined && children.length > 0) {
          item.children = that.treeMap_name(
            children,
            typid,
            name,
            showTyp,
            rdx
          )
        }
        newArr.push(item)
      })
      return newArr
    },
    // 遍历树形菜单数据
    treeMap_isdisable(data, typid) {
      const newArr = []
      const that = this
      data.map(function(item) {
        if (item.typID == typid || item.prtID == typid) {
          item.isdisable = true
          const children = item.children
          if (
            children != null &&
            children != undefined &&
            children.length > 0
          ) {
            item.children = that.treeMap_isdisable(children, item.typID)
          }
        } else {
          const children = item.children
          if (
            children != null &&
            children != undefined &&
            children.length > 0
          ) {
            item.children = that.treeMap_isdisable(children, typid)
          }
        }
        newArr.push(item)
      })
      return newArr
    },
    // 获取树形菜单
    getTree(oldArr, prtid) {
      const newArr = []
      const that = this
      oldArr.map(function(item) {
        if (item.prtID == prtid || item.prtID == '') {
          var obj = {
            label: item.name,
            prtID: item.prtID,
            typID: item.typID,
            stt: item.stt,
            isDelete: item.isDelete,
            isVisible: false,
            posTyp: item.posTyp,
            showTyp: item.showTyp,
            rdx: item.rdx,
            isdisable: false
          }
          var child = that.getTree(oldArr, item.typID)
          if (child.length > 0) {
            obj.children = child
            if (obj.stt == 0) {
              obj.children = that.treeMap_isdisable(child, obj.typID)
            }
          }
          newArr.push(obj)
        }
      })
      return newArr
    },
    // 获取节点数据
    getNode(data) {
      this.form.name = data.label
      this.form.typID = data.typID
      this.oldprtID = this.form.prtID = data.prtID == null ? '' : data.prtID
      this.form.rdx = data.rdx
      this.form.stt = data.stt
      this.form.isDelete = data.isDelete
      this.form.posTyp = data.posTyp
      this.form.showTyp = data.showTyp
      this.getnodedata = data
      this.fetchData()
    }
  }
}
// 后台事件
var backstage = {
  // 获取节点数据
  getNode: function(thisobj, params) {
    AjaxToken(
      thisobj,
      'GetDesByPage',
      params,
      'post',
      function(res) {
        thisobj.tableloading = false
        var body = res.data.data
        if (thisobj.form.showTyp == 0) {
          // 单个文档
          if (body.rows != null && body.rows.length > 0) {
            thisobj.desform = body.rows[0]
          }
          thisobj.$refs.editor.setContent(thisobj.desform.content || '')
        } else {
          // 列表
          if (body.rows != null && body.rows.length > 0) {
            body.rows.forEach((element) => {
              element.stDt =
                element.stDt != null ? element.stDt.replace('T', ' ') : null
              element.etDt =
                element.etDt != null ? element.etDt.replace('T', ' ') : null
              element.isVisible = false
            })
            thisobj.deslist = body.rows
            thisobj.listQuery.page = body.page
            thisobj.listQuery.total = body.records
          }
        }
      },
      function(err) {
        thisobj.tableloading = false
      }
    )
  },
  // 获取产品文档分类
  getProductDocTyp: function(thisobj, params) {
    AjaxToken(
      thisobj,
      'GetAllProductDocTyp',
      params,
      'post',
      function(res) {
        thisobj.treeloading = false
        const Lst = res.data.data
        thisobj.TypList = res.data.data
        if (Lst.length > 0) {
          // 递归树形数组
          thisobj.Treedata = thisobj.getTree(Lst, null)

          // 初始化加载第一条的数据
          thisobj.getNode(thisobj.Treedata[0])
        }
      },
      function(err) {
        thisobj.treeloading = false
      }
    )
  },
  // 添加节点
  append: function(thisobj, params) {
    AjaxToken(
      thisobj,
      'SaveProductDocTyp',
      params,
      'post',
      function(res) {
        if (res.data.success) {
          thisobj.dialogFormVisible = false
          thisobj.getProductDocTyp()
        }
        thisobj.$message({
          showClose: true,
          message: res.data.message,
          type: res.data.success ? 'success' : 'error'
        })
      },
      function(err) {}
    )
  },
  // 显示隐藏或者删除
  IsShow: function(thisobj, params, node, data, typ) {
    AjaxToken(
      thisobj,
      'IsShowProductDocTyp',
      params,
      'post',
      function(res) {
        thisobj.treeloading = false
        thisobj.$message({
          showClose: true,
          message: res.data.message,
          type: res.data.success ? 'success' : 'error',
          duration: 3000
        })

        if (res.data.success) {
          if (typ == '1') {
            thisobj.remove(node, data)
          } else {
            thisobj.Treedata = JSON.parse(
              JSON.stringify(
                thisobj.treeMap_stt(
                  thisobj.Treedata,
                  data.typID,
                  data.stt == 0 ? 1 : 0
                )
              )
            )
          }
        }
      },
      function(err) {
        thisobj.treeloading = false
        thisobj.$message({
          showClose: true,
          message: err.message,
          type: 'error',
          duration: 2000
        })
      }
    )
  },
  // 保存产品文档说明数据
  saveDes: function(thisobj, params, showTyp) {
    AjaxToken(
      thisobj,
      'SaveDes',
      params,
      'post',
      function(res) {
        thisobj.loading = false
        thisobj.$message({
          showClose: true,
          message: res.data.message,
          type: res.data.success ? 'success' : 'error',
          duration: 2000
        })
        if (res.data.success) {
          thisobj.dialogDesVisible = false
          if (thisobj.oldprtID != thisobj.form.prtID) {
            thisobj.getProductDocTyp()
          } else {
            thisobj.Treedata = JSON.parse(
              JSON.stringify(
                thisobj.treeMap_name(
                  thisobj.Treedata,
                  thisobj.form.typID,
                  thisobj.form.name,
                  thisobj.form.showTyp,
                  thisobj.form.rdx
                )
              )
            )
            if (showTyp == 1) {
              thisobj.fetchData()
            }
          }
        }
      },
      function(err) {
        thisobj.loading = false
      }
    )
  }
}
</script>

<style  lang="scss" scoped>
.el-header {
  line-height: 60px;
}
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
  text-align: center;
}

.el-aside {
  // background-color: #d3dce6;
  color: #333;
  text-align: center;
  height: auto;
  margin-bottom: 0px;
  padding: 10px 10px;
  width: 35%;
}

.el-main {
  width: 64%;
  // background-color: #d3dce6;
  color: #333;
  text-align: center;
  padding: 10px 10px;
  height: auto;
  min-height: 765px;
}

body > .el-container {
  margin-bottom: 0px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.actiontable {
  width: 100%;
  height: 100%;
  max-height: 660px;
  overflow: auto;
}
.moduletabe {
  width: 100%;
  height: 100%;
  max-height: 745px;
  overflow: auto;
}
.pagination {
  background-color: white;
  height: 85px;
  padding-top: 25px !important;
  margin-top: inherit;
}
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: #606266;
  padding-right: 8px;
}
.el-tree-node__content {
  margin-bottom: 2px;
}
</style>
<style>
.productdoctypcontent {
  background-color: #ffffff;
  font-size: 14px;
}
.productdoctypcontent .item {
  float: left;
  margin-right: 10px;
  text-align: left;
  line-height: 35px;
  margin-bottom: 15px;
}
.itemcontent {
  clear: both;
  width: 90%;
  margin-left: 5%;
  line-height: 35px;
}
.namediv {
  float: left;
  width: 120px;
  text-align: right;
}
.productdoctypcontent .dialog-footer {
  text-align: right;
  margin-right: 5%;
  margin-top: 1%;
}
.iteminput {
  width: 300px;
}
.productdoctypcontent .el-form-item--medium .el-form-item__label {
  text-align: right;
  font-weight: 400;
}

.productdoctypcontent .el-collapse-item__header {
  /* margin-left: 10px; */
  text-indent: 10px;
  font-weight: 700;
}
.productdoctypcontent .adddesdiv {
  text-align: left;
}
</style>
